fix: prevent unwanted block split during IME composition on WKWebView#89
Merged
fix: prevent unwanted block split during IME composition on WKWebView#89
Conversation
On WebKit, committing IME text without conversion on an empty list item triggers a DOM-level block split that ProseMirror's observer converts into unwanted structural transactions. A layered defence blocks those transactions, cleans up orphaned DOM nodes, and forces ProseMirror to re-render from its authoritative state. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Apply biome auto-fixes: sort imports in index.ts and fix formatting (trailing commas, line wrapping) in imeCompositionGuard.ts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
imeCompositionGuardBlockNote extension that prevents unwanted line breaks during IME composition on Tauri's WKWebViewReplaceStepwithstructure: trueandReplaceAroundStep) that WebKit generates when it temporarily empties a list item during IME text commitmentProblem
On WKWebView, when the user commits IME text without conversion on an empty list item (e.g., typing "あ" + Enter), the browser temporarily removes the composition text via
deleteCompositionText, which empties the paragraph. WebKit then splits the list item (exiting an empty list item). When the committed text is re-inserted viainsertFromComposition, it lands in the new block, causing an unwanted block split.This does not occur when text already exists in the list item, because the paragraph never becomes empty.
Fix
A layered defence approach:
filterTransactionblocks structural steps during composition and also blocks the duplicate text insertion that follows (caused by position mismatch from the blocked structural step)compositionendremoves orphaned block container elements and forces ProseMirror to re-render the DOM from its statecontentEditable = 'plaintext-only'during composition prevents block-level element creation (covers "with conversion" case)keydowncapture andhandleKeyDownprop block Enter during the composing window as additional safetyTest plan
*) and press Enter without conversion → no line break, text "あ" is committed* こんにちは) and press Enter without conversion → no line break (existing behavior preserved)🤖 Generated with Claude Code